import logging

import app
import requests


class EmpApi:

    # 新增员工
    def add_emp(self, token, json_dict):
        url = app.BASE_HOST + "/api/sys/user"
        header_dict = {"Authorization": token}
        res = requests.post(url=url, json=json_dict, headers=header_dict)
        logging.info("新增员工接口返回的响应体数据：{}".format(res.json()))
        return res

    # 查询员工
    def query_emp(self, token, id):
        url = app.BASE_HOST + "/api/sys/user/{}".format(id)
        header_dict = {"Authorization": token}
        res = requests.get(url=url, headers=header_dict)
        logging.info("查询员工接口返回的响应体数据：{}".format(res.json()))
        return res

    # 修改员工
    def update_emp(self, token, id, json_dict):
        url = app.BASE_HOST + "/api/sys/user/{}".format(id)
        header_dict = {"Authorization": token}
        res = requests.put(url=url, headers=header_dict, json=json_dict)
        logging.info("修改员工接口返回的响应体数据：{}".format(res.json()))
        return res

    # 删除员工
    def del_emp(self, token, id):
        url = app.BASE_HOST + "/api/sys/user/{}".format(id)
        header_dict = {"Authorization": token}
        res = requests.delete(url=url, headers=header_dict)
        logging.info("删除员工接口返回的响应体数据：{}".format(res.json()))
        return res
